package cn.edu.cqut.mdm.core.publish.json;

import cn.edu.cqut.mdm.container.LocalDefinedModuleContainer;
import cn.edu.cqut.mdm.container.NetworkPublishedModuleContainer;
import cn.edu.cqut.mdm.core.module.ModuleEntity;
import cn.edu.cqut.mdm.core.module.PublishStatus.Status;
import cn.edu.cqut.mdm.core.publish.Publisher;
import cn.edu.cqut.mdm.core.publisherdispatcher.JsonPublisherDispatcher;

public class JsonPublisher implements Publisher{
	@Override
	public void publish(ModuleEntity module) {
		module.getPublishStatus(new JsonPublisherDispatcher().getName()).setStatus(Status.PUBLISHED);
		NetworkPublishedModuleContainer.getInstance().addModule(module.toRemoteModuleEntity(new JsonPublisherDispatcher().getName()));
	}

	@Override
	public void unpublish(String moduleUid) {
		LocalDefinedModuleContainer.getInstance().getModule(moduleUid).getPublishStatus(new JsonPublisherDispatcher().getName()).setStatus(Status.UNPUBLISHED);
		NetworkPublishedModuleContainer.getInstance().delModule(moduleUid);
	}

}
